package com.yanqu.road.server.cmd.strongholdwar.eliminate;

import com.yanqu.road.entity.activity.stronghold.CrossStrongholdEliminateDefendPatrons;
import com.yanqu.road.entity.activity.stronghold.CrossStrongholdEliminateUnion;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.strongholdwar.CrossStrongholdActivityMgr;
import com.yanqu.road.server.manager.strongholdwar.CrossStrongholdMgr;
import com.yanqu.road.server.manager.strongholdwar.CrossStrongholdRankMgr;
import com.yanqu.road.server.pb.CrossStrongholdPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_STRONGHOLD_CHOOSE_UNION,desc = "")
public class StrongholdChooseChallengeUniomCmd extends CrossUnionCommand {
    private int activityId;
    private int id;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        StrongholdWarProto.CrossChooseChallengeUnionReqMsg req = StrongholdWarProto.CrossChooseChallengeUnionReqMsg.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        id = req.getId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossStrongholdEliminateUnion union = CrossStrongholdMgr.chooseChallengeUnion(activityId, groupId, id);
        CrossStrongholdEliminateDefendPatrons defendPatrons = union.getCurDefendPatrons();
        StrongholdWarProto.ChooseChallengeUnionRespMsg.Builder resp = StrongholdWarProto.ChooseChallengeUnionRespMsg.newBuilder();
        resp.setRet(0);
        if (defendPatrons != null) {
            StrongholdWarProto.EliminateChallengePatronsDataMsg.Builder patronsMsg = CrossStrongholdPb.parseEliminateChallengePatronsMsg(defendPatrons);
            resp.setPatrons(patronsMsg);
        }
        int rank = CrossStrongholdRankMgr.getCrossActivityUnionRank(activityId, CrossStrongholdActivityMgr.CONDITION_TYPE_ELIMINATE_UNION, union.getServerId(), union.getUnionUid());
        resp.setUnionInfo(CrossStrongholdPb.parseEliminateUnionMsg(union, rank));
        YanQuMessage msg = YanQuMessageUtils.buildMessage(ClientProtocol.U_STRONGHOLD_WAR_ELIMINATION_ENTER_UNION, resp);
        MessageHelper.sendPacket(serverId,packet.getPlayerId(),msg);
    }

    @Override
    public void sendData() {

    }
}
